Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Command pattern</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Command_pattern"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Command_pattern rootpage-Command_pattern skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Command pattern</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1305433154">
/* start https://en.wikipedia.org/ */


.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}


/* end https://en.wikipedia.org/ */
</style>
<p>In <a href="Object-oriented_programming" title="Object-oriented programming">object-oriented programming</a>, the <b>command pattern</b> is a <a href="Behavioral_pattern" title="Behavioral pattern">behavioral</a> <a href="Design_pattern_(computer_science)" class="mw-redirect" title="Design pattern (computer science)">design pattern</a> in which an object is used to <a href="Information_hiding" title="Information hiding">encapsulate</a> all information needed to perform an action or trigger an event at a later time. This information includes the method name, the object that owns the method and values for the method parameters.
</p><p>Four terms always associated with the command pattern are <i>command</i>, <i>receiver</i>, <i>invoker</i> and <i>client</i>. A <i>command</i> object knows about <i>receiver</i> and invokes a method of the receiver. Values for parameters of the receiver method are stored in the command. The receiver object to execute these methods is also stored in the command object by <a href="Object_composition#Aggregation" title="Object composition">aggregation</a>. The <i>receiver</i> then does the work when the <code>execute()</code> method in <i>command</i> is called. An <i>invoker</i> object knows how to execute a command, and optionally does bookkeeping about the command execution. The invoker does not know anything about a concrete command, it knows only about the command <i>interface</i>. Invoker object(s), command objects and receiver objects are held by a <i>client</i> object. The <i>client</i> decides which receiver objects it assigns to the command objects, and which commands it assigns to the invoker. The client decides which commands to execute at which points. To execute a command, it passes the command object to the invoker object.
</p><p>Using command objects makes it easier to construct general components that need to delegate, sequence or execute method calls at a time of their choosing without the need to know the class of the method or the method parameters. Using an invoker object allows bookkeeping about command executions to be conveniently performed, as well as implementing different modes for commands, which are managed by the invoker object, without the need for the client to be aware of the existence of bookkeeping or modes.
</p><p>The central ideas of this design pattern closely mirror the semantics of <a href="First-class_function" title="First-class function">first-class functions</a> and <a href="Higher-order_function" title="Higher-order function">higher-order functions</a> in <a href="Functional_programming_language" class="mw-redirect" title="Functional programming language">functional programming languages</a>. Specifically, the invoker object is a higher-order function of which the command object is a first-class argument.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Overview">Overview</h2></div>
<p>The command<sup id="cite_ref-GoF_1-0" class="reference"><a href="#cite_note-GoF-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
design pattern is one of the twenty-three well-known <i><a href="Design_Patterns" title="Design Patterns">GoF design patterns</a></i> that describe how to solve recurring design problems to design flexible and reusable object-oriented software, that is, objects that are easier to implement, change, test, and reuse.
</p><p>Using the command design pattern can solve these problems:<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup>
</p>
<ul><li>Coupling the invoker of a request to a particular request should be avoided. That is, hard-wired requests should be avoided.</li>
<li>It should be possible to configure an object (that invokes a request) with a request.</li></ul>
<p>Implementing (hard-wiring) a request directly into a class is inflexible because it couples the class to a particular request at compile-time, which makes it impossible to specify a request at run-time.
</p><p>Using the command design pattern describes the following solution:
</p>
<ul><li>Define separate (command) objects that encapsulate a request.</li>
<li>A class delegates a request to a command object instead of implementing a particular request directly.</li></ul>
<p>This enables one to configure a class with a command object that is used to perform a request. The class is no longer coupled to a particular request and has no knowledge (is independent) of how the request is carried out.
</p><p>See also the UML class and sequence diagram below.
</p>
<div class="mw-heading mw-heading2"><h2 id="Structure">Structure</h2></div>
<div class="mw-heading mw-heading3"><h3 id="UML_class_and_sequence_diagram">UML class and sequence diagram</h3></div>

<p>In the above <a href="Unified_Modeling_Language" title="Unified Modeling Language">UML</a> <a href="Class_diagram" title="Class diagram">class diagram</a>, the <code>Invoker</code> class doesn't implement a request directly.
Instead, <code>Invoker</code> refers to the <code>Command</code> interface to perform a request (<code>command.execute()</code>), which makes the <code>Invoker</code> independent of how the request is performed.
The <code>Command1</code> class implements the <code>Command</code> interface by performing an action on a receiver (<code>receiver1.action1()</code>).
</p><p>The <a href="Unified_Modeling_Language" title="Unified Modeling Language">UML</a> <a href="Sequence_diagram" title="Sequence diagram">sequence diagram</a>
shows the run-time interactions: The <code>Invoker</code> object calls <code>execute()</code> on a <code>Command1</code> object.
<code>Command1</code> calls <code>action1()</code> on a <code>Receiver1</code> object,
which performs the request.
</p>
<div class="mw-heading mw-heading3"><h3 id="UML_class_diagram">UML class diagram</h3></div>

<div class="mw-heading mw-heading2"><h2 id="Uses">Uses</h2></div>
<dl><dt>GUI buttons and menu items</dt>
<dd>In <a href="Swing_(Java)" title="Swing (Java)">Swing</a> and <a href="Borland" title="Borland">Borland</a> <a href="Delphi_(software)" title="Delphi (software)">Delphi</a> programming, an <code><a rel="nofollow" class="external text" href="https://docs.oracle.com/en/java/javase/24/docs/api/java.desktop/javax/swing/Action.html">Action</a></code> is a command object. In addition to the ability to perform the desired command, an <style data-mw-deduplicate="TemplateStyles:r886049734">
/* start https://en.wikipedia.org/ */


.mw-parser-output .monospaced{font-family:monospace,monospace}


/* end https://en.wikipedia.org/ */
</style><span class="monospaced">Action</span> may have an associated icon, <a href="Keyboard_shortcut" title="Keyboard shortcut">keyboard shortcut</a>, <a href="Tooltip" title="Tooltip">tooltip</a> text, and so on. A toolbar button or menu item component may be completely initialized using only the <span class="monospaced">Action</span> object.</dd>
<dt><a href="Macro_(computer_science)" title="Macro (computer science)">Macro</a> recording</dt>
<dd>If all user actions are represented by command objects, a program can record a sequence of actions simply by keeping a list of the command objects as they are executed. It can then "play back" the same actions by executing the same command objects again in sequence. If the program embeds a scripting engine, each command object can implement a <span class="monospaced">toScript()</span> method, and user actions can then be easily recorded as scripts.</dd>
<dt><a href="Code_mobility" title="Code mobility">Mobile code</a></dt>
<dd>Using languages such as Java where code can be streamed/slurped from one location to another via URLClassloaders and Codebases the commands can enable new behavior to be delivered to remote locations (EJB Command, Master Worker).</dd>
<dt>Multi-level <a href="Undo" title="Undo">undo</a></dt>
<dd>If all user actions in a program are implemented as command objects, the program can keep a stack of the most recently executed commands. When the user wants to undo a command, the program simply pops the most recent command object and executes its <span class="monospaced">undo()</span> method.</dd>
<dt>Networking</dt>
<dd>It is possible to send whole command objects across the network to be executed on the other machines, for example player actions in computer games.</dd>
<dt>Parallel processing</dt>
<dd>Where the commands are written as tasks to a shared resource and executed by many threads in parallel (possibly on remote machines; this variant is often referred to as the Master/Worker pattern)</dd>
<dt><a href="Progress_bar" title="Progress bar">Progress bars</a></dt>
<dd>Suppose a program has a sequence of commands that it executes in order. If each command object has a <span class="monospaced">getEstimatedDuration()</span> method, the program can easily estimate the total duration. It can show a progress bar that meaningfully reflects how close the program is to completing all the tasks.</dd>
<dt><a href="Thread_pool" title="Thread pool">Thread pools</a></dt>
<dd>A typical, general-purpose thread pool class might have a public <span class="monospaced">addTask()</span> method that adds a work item to an internal queue of tasks waiting to be done. It maintains a pool of threads that execute commands from the queue. The items in the queue are command objects. Typically these objects implement a common interface such as <span class="monospaced">java.lang.Runnable</span> that allows the thread pool to execute the command even though the thread pool class itself was written without any knowledge of the specific tasks for which it would be used.</dd>
<dt><a href="Database_transaction" title="Database transaction">Transactional</a> behavior</dt>
<dd>Similar to undo, a <a href="Database_engine" title="Database engine">database engine</a> or software installer may keep a list of operations that have been or will be performed. Should one of them fail, all others can be reversed or discarded (usually called <i>rollback</i>). For example, if two database tables that refer to each other must be updated, and the second update fails, the transaction can be rolled back, so that the first table does not now contain an invalid reference.</dd>
<dt><a href="Wizard_(software)" title="Wizard (software)">Wizards</a></dt>
<dd>Often a wizard presents several pages of configuration for a single action that happens only when the user clicks the "Finish" button on the last page. In these cases, a natural way to separate user interface code from application code is to implement the wizard using a command object. The command object is created when the wizard is first displayed. Each wizard page stores its GUI changes in the command object, so the object is populated as the user progresses. "Finish" simply triggers a call to <span class="monospaced">execute()</span>. This way, the command class will work.</dd></dl>
<div class="mw-heading mw-heading2"><h2 id="Terminology">Terminology</h2></div>
<p>The terminology used to describe command pattern implementations is not consistent and can therefore be confusing.
This is the result of <a href="Ambiguity" title="Ambiguity">ambiguity</a>, the use of <a href="Synonyms" class="mw-redirect" title="Synonyms">synonyms</a>, and implementations that may obscure the original pattern by going well beyond it.
</p>
<ol><li>Ambiguity.
<ol><li>The term <b>command</b> is ambiguous. For example, <i>move up, move up</i> may refer to a single (move up) command that should be executed twice, or it may refer to two commands, each of which happens to do the same thing (move up). If the former command is added twice to an undo stack, both items on the stack refer to the same command instance. This may be appropriate when a command can always be undone the same way (e.g. move down). Both the <a href="Gang_of_Four_(software)" class="mw-redirect" title="Gang of Four (software)">Gang of Four</a> and the <a href="#Java">Java example below</a> use this interpretation of the term <i>command</i>. On the other hand, if the latter commands are added to an undo stack, the stack refers to two separate objects. This may be appropriate when each object on the stack must contain information that allows the command to be undone. For example, to undo a <i>delete selection</i> command, the object may contain a copy of the deleted text so that it can be re-inserted, if the <i>delete selection</i> command must be undone. Note that using a separate object for each invocation of a command is also an example of the <a href="Chain_of_responsibility_pattern" class="mw-redirect" title="Chain of responsibility pattern">chain of responsibility pattern</a>.</li>
<li>The term <b>execute</b> is also ambiguous. It may refer to running the code identified by the command object's <i>execute</i> method. However, in Microsoft's <a href="Windows_Presentation_Foundation" title="Windows Presentation Foundation">Windows Presentation Foundation</a> a command is considered to have been executed when the command's <i>execute</i> method has been invoked, but that does not necessarily mean that the application code has run. That occurs only after some further event processing.</li></ol></li>
<li>Synonyms and <a href="Homonyms" class="mw-redirect" title="Homonyms">homonyms</a>.
<ol><li><b>Client, Source, Invoker</b>: the button, toolbar button, or menu item clicked, the shortcut key pressed by the user.</li>
<li><b>Command Object, Routed Command Object, Action Object</b>: a singleton object (e.g. there is only one <code>CopyCommand</code> object), which knows about shortcut keys, button images, command text, etc. related to the command. A source or invoker object calls the Command or Action object's execute or performAction method. The Command/Action object notifies the appropriate source/invoker objects when the availability of a command/action has changed. This allows buttons and menu items to become inactive (grayed out) when a command/action cannot be executed/performed.</li>
<li><b>Receiver, Target Object</b>: the object that is about to be copied, pasted, moved, etc. The receiver object owns the method that is called by the command's <i>execute</i> method. The receiver is typically also the target object. For example, if the receiver object is a <i>cursor</i> and the method is called <code>moveUp</code>, then one would expect that the cursor is the target of the <code>moveUp</code> action. On the other hand, if the code is defined by the command object itself, the target object will be a different object entirely.</li>
<li><b>Command Object, routed event arguments, event object</b>: the object that is passed from the source to the Command/Action object, to the Target object to the code that does the work. Each button click or shortcut key results in a new command/event object. Some implementations add more information to the command/event object as it is being passed from one object (e.g. <code>CopyCommand</code>) to another (e.g. document section). Other implementations put command/event objects in other event objects (like a box inside a bigger box) as they move along the line, to avoid naming conflicts. (See also <a href="Chain_of_responsibility_pattern" class="mw-redirect" title="Chain of responsibility pattern">chain of responsibility pattern</a>.)</li>
<li><b>Handler, <code>ExecutedRoutedEventHandler</code>, method, function</b>: the actual code that does the copying, pasting, moving, etc. In some implementations the handler code is part of the command/action object. In other implementations the code is part of the Receiver/Target Object, and in yet other implementations the handler code is kept separate from the other objects.</li>
<li><b>Command Manager, Undo Manager, Scheduler, Queue, Dispatcher, Invoker</b>: an object that puts command/event objects on an undo stack or redo stack, or that holds on to command/event objects until other objects are ready to act on them, or that routes the command/event objects to the appropriate receiver/target object or handler code.</li></ol></li>
<li>Implementations that go well beyond the original command pattern.
<ol><li>Microsoft's <a rel="nofollow" class="external text" href="http://msdn.microsoft.com/en-us/library/ms752308.aspx">Windows Presentation Foundation</a> (WPF), introduces routed commands, which combine the command pattern with event processing. As a result, the command object no longer contains a reference to the target object nor a reference to the application code. Instead, invoking the command object's <i>execute</i> command results in a so-called <i>Executed Routed Event</i> that during the event's tunneling or bubbling may encounter a so-called <i>binding</i> object that identifies the target and the application code, which is executed at that point.</li></ol></li></ol>
<div class="mw-heading mw-heading2"><h2 id="Example">Example</h2></div>
<p>This C++14 implementation is based on the pre C++98 implementation in the book.
</p>
<div class="mw-highlight mw-highlight-lang-c++ mw-content-ltr" dir="ltr"><pre><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;iostream&gt;</span>
<span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;memory&gt;</span>

<span class="k">class</span><span class="w"> </span><span class="nc">Command</span><span class="w"> </span><span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
<span class="w"> </span><span class="c1">// declares an interface for executing an operation.</span>
<span class="w"> </span><span class="k">virtual</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="n">execute</span><span class="p">()</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
<span class="w"> </span><span class="k">virtual</span><span class="w"> </span><span class="o">~</span><span class="n">Command</span><span class="p">()</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">default</span><span class="p">;</span>
<span class="k">protected</span><span class="o">:</span>
<span class="w"> </span><span class="n">Command</span><span class="p">()</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">default</span><span class="p">;</span>
<span class="p">};</span>

<span class="k">template</span><span class="w"> </span><span class="o">&lt;</span><span class="k">typename</span><span class="w"> </span><span class="nc">Receiver</span><span class="o">&gt;</span>
<span class="k">class</span><span class="w"> </span><span class="nc">SimpleCommand</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="n">Command</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="c1">// ConcreteCommand</span>
<span class="k">public</span><span class="o">:</span>
<span class="w"> </span><span class="k">typedef</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="p">(</span><span class="n">Receiver</span><span class="o">::*</span><span class="w"> </span><span class="n">Action</span><span class="p">)();</span>
<span class="w"> </span><span class="c1">// defines a binding between a Receiver object and an action.</span>
<span class="w"> </span><span class="n">SimpleCommand</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">Receiver</span><span class="o">&gt;</span><span class="w"> </span><span class="n">receiver_</span><span class="p">,</span><span class="w"> </span><span class="n">Action</span><span class="w"> </span><span class="n">action_</span><span class="p">)</span><span class="w"> </span><span class="o">:</span>
<span class="w"> </span><span class="n">receiver</span><span class="p">(</span><span class="n">receiver_</span><span class="p">.</span><span class="n">get</span><span class="p">()),</span><span class="w"> </span><span class="n">action</span><span class="p">(</span><span class="n">action_</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="n">SimpleCommand</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">SimpleCommand</span><span class="o">&amp;</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">delete</span><span class="p">;</span><span class="w"> </span><span class="c1">// rule of three</span>
<span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="n">SimpleCommand</span><span class="o">&amp;</span><span class="w"> </span><span class="k">operator</span><span class="o">=</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="n">SimpleCommand</span><span class="o">&amp;</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="k">delete</span><span class="p">;</span>
<span class="w"> </span><span class="c1">// implements execute by invoking the corresponding operation(s) on Receiver.</span>
<span class="w"> </span><span class="k">virtual</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">execute</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="p">(</span><span class="n">receiver</span><span class="o">-&gt;*</span><span class="n">action</span><span class="p">)();</span>
<span class="w"> </span><span class="p">}</span>
<span class="k">private</span><span class="o">:</span>
<span class="w"> </span><span class="n">Receiver</span><span class="o">*</span><span class="w"> </span><span class="n">receiver</span><span class="p">;</span>
<span class="w"> </span><span class="n">Action</span><span class="w"> </span><span class="n">action</span><span class="p">;</span>
<span class="p">};</span>

<span class="k">class</span><span class="w"> </span><span class="nc">MyClass</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="c1">// Receiver</span>
<span class="k">public</span><span class="o">:</span>
<span class="w"> </span><span class="c1">// knows how to perform the operations associated with carrying out a request. Any class may serve as a Receiver.</span>
<span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="n">action</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">"MyClass::action</span><span class="se">\n</span><span class="s">"</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">};</span>

<span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="c1">// The smart pointers prevent memory leaks.</span>
<span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">shared_ptr</span><span class="o">&lt;</span><span class="n">MyClass</span><span class="o">&gt;</span><span class="w"> </span><span class="n">receiver</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">make_shared</span><span class="o">&lt;</span><span class="n">MyClass</span><span class="o">&gt;</span><span class="p">();</span>
<span class="w"> </span><span class="c1">// ...</span>
<span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">unique_ptr</span><span class="o">&lt;</span><span class="n">Command</span><span class="o">&gt;</span><span class="w"> </span><span class="n">command</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="n">make_unique</span><span class="o">&lt;</span><span class="n">SimpleCommand</span><span class="o">&lt;</span><span class="n">MyClass</span><span class="o">&gt;</span><span class="w"> </span><span class="o">&gt;</span><span class="p">(</span><span class="n">receiver</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">MyClass</span><span class="o">::</span><span class="n">action</span><span class="p">);</span>
<span class="w"> </span><span class="c1">// ...</span>
<span class="w"> </span><span class="n">command</span><span class="o">-&gt;</span><span class="n">execute</span><span class="p">();</span>
<span class="p">}</span>
</pre></div>
<p>The program output is
</p>
<div class="mw-highlight mw-highlight-lang-c++ mw-content-ltr" dir="ltr"><pre><span class="n">MyClass</span><span class="o">::</span><span class="n">action</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="Batch_queue" class="mw-redirect" title="Batch queue">Batch queue</a></li>
<li><a href="Closure_(computer_science)" class="mw-redirect" title="Closure (computer science)">Closure</a></li>
<li><a href="Command_queue" title="Command queue">Command queue</a></li>
<li><a href="Function_object" title="Function object">Function object</a></li>
<li><a href="Job_scheduler" title="Job scheduler">Job scheduler</a></li>
<li><a href="Model%E2%80%93view%E2%80%93controller" title="Model–view–controller">Model–view–controller</a></li>
<li><a href="Priority_queue" title="Priority queue">Priority queue</a></li>
<li><a href="Software_design_pattern" title="Software design pattern">Software design pattern</a></li>
<li><i><a href="Design_Patterns" title="Design Patterns">Design Patterns</a></i> (book)</li></ul>
<div class="mw-heading mw-heading2"><h2 id="History">History</h2></div>
<p>The first published mention of using a Command class to implement interactive systems seems to be a 1985 article by Henry Lieberman.<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup> The first published description of a (multiple-level) undo-redo mechanism, using a Command class with <i>execute</i> and <i>undo</i> methods, and a history list, appears to be the first (1988) edition of <a href="Bertrand_Meyer" title="Bertrand Meyer">Bertrand Meyer</a>'s book <a href="Object-oriented_Software_Construction" class="mw-redirect" title="Object-oriented Software Construction">Object-oriented Software Construction</a>,<sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup> section 12.2.
</p>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */


.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}


/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-GoF-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-GoF_1-0">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */


.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}


/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFErich_GammaRichard_HelmRalph_JohnsonJohn_Vlissides1994" class="citation book cs1">Erich Gamma; Richard Helm; Ralph Johnson; John Vlissides (1994). <span class="id-lock-registration" title="Free registration required"><a rel="nofollow" class="external text" href="https://archive.org/details/designpatternsel00gamm/page/233"><i>Design Patterns: Elements of Reusable Object-Oriented Software</i></a></span>. Addison Wesley. pp.&nbsp;<a rel="nofollow" class="external text" href="https://archive.org/details/designpatternsel00gamm/page/233">233ff</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>0-201-63361-2</bdi>.</cite></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20200923124858/http://w3sdesign.com/?gr=b02&amp;ugr=proble">"The Command design pattern - Problem, Solution, and Applicability"</a>. <i>w3sDesign.com</i>. Archived from <a rel="nofollow" class="external text" href="http://w3sdesign.com/?gr=b02&amp;ugr=proble">the original</a> on 2020-09-23<span class="reference-accessdate">. Retrieved <span class="nowrap">2017-08-12</span></span>.</cite></span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20200923120537/http://w3sdesign.com/?gr=b02&amp;ugr=struct">"The Command design pattern - Structure and Collaboration"</a>. <i>w3sDesign.com</i>. Archived from <a rel="nofollow" class="external text" href="http://w3sdesign.com/?gr=b02&amp;ugr=struct">the original</a> on September 23, 2020<span class="reference-accessdate">. Retrieved <span class="nowrap">2017-08-12</span></span>.</cite></span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><cite id="CITEREFLieberman1985" class="citation journal cs1">Lieberman, Henry (1985). "There's more to menu systems than meets the screen". <i>ACM SIGGRAPH Computer Graphics</i>. <b>19</b> (3): <span class="nowrap">181–</span>189. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F325165.325235">10.1145/325165.325235</a>.</cite></span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><cite id="CITEREFMeyer1988" class="citation book cs1"><a href="Bertrand_Meyer" title="Bertrand Meyer">Meyer, Bertrand</a> (1988). <i>Object-Oriented Software Construction</i> (1st&nbsp;ed.). Prentice-Hall.</cite></span>
</li>
</ol></div></div>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1290876196">
/* start https://en.wikipedia.org/ */


.mw-parser-output .side-box{margin:4px 0;box-sizing:border-box;border:1px solid #aaa;font-size:88%;line-height:1.25em;background-color:var(--background-color-interactive-subtle,#f8f9fa);display:flow-root}.mw-parser-output .infobox .side-box{font-size:100%}.mw-parser-output .side-box-abovebelow,.mw-parser-output .side-box-text{padding:0.25em 0.9em}.mw-parser-output .side-box-image{padding:2px 0 2px 0.9em;text-align:center}.mw-parser-output .side-box-imageright{padding:2px 0.9em 2px 0;text-align:center}@media(min-width:500px){.mw-parser-output .side-box-flex{display:flex;align-items:center}.mw-parser-output .side-box-text{flex:1;min-width:0}}@media(min-width:720px){.mw-parser-output .side-box{width:238px}.mw-parser-output .side-box-right{clear:right;float:right;margin-left:1em}.mw-parser-output .side-box-left{margin-right:1em}}


/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1237033735">
/* start https://en.wikipedia.org/ */


@media print{body.ns-0 .mw-parser-output .sistersitebox{display:none!important}}@media screen{html.skin-theme-clientpref-night .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .sistersitebox img[src*="Wiktionary-logo-en-v2.svg"]{background-color:white}}


/* end https://en.wikipedia.org/ */
</style><div class="side-box side-box-right sistersitebox"><style data-mw-deduplicate="TemplateStyles:r1126788409">
/* start https://en.wikipedia.org/ */


.mw-parser-output .plainlist ol,.mw-parser-output .plainlist ul{line-height:inherit;list-style:none;margin:0;padding:0}.mw-parser-output .plainlist ol li,.mw-parser-output .plainlist ul li{margin-bottom:0}


/* end https://en.wikipedia.org/ */
</style>
<div class="side-box-flex">
<div class="side-box-image"><span class="noviewer" typeof="mw:File"></span></div>
<div class="side-box-text plainlist">Wikimedia Commons has media related to <span style="font-weight: bold; font-style: italic;"><a href="https://commons.wikimedia.org/wiki/Category:Command_pattern" class="extiw external" title="commons:Category:Command pattern">Command pattern</a></span>.</div></div>
</div>
<div class="side-box side-box-right sistersitebox">
<div class="side-box-flex">
<div class="side-box-image"><span class="noviewer" typeof="mw:File"></span></div>
<div class="side-box-text plainlist">The Wikibook <i><a href="https://en.wikibooks.org/wiki/Computer_Science_Design_Patterns" class="extiw external" title="wikibooks:Computer Science Design Patterns">Computer Science Design Patterns</a></i> has a page on the topic of: <i><b><a href="https://en.wikibooks.org/wiki/Computer_Science_Design_Patterns/Command" class="extiw external" title="wikibooks:Computer Science Design Patterns/Command">Command implementations in various languages</a></b></i></div></div>
</div>
<ul><li><a rel="nofollow" class="external text" href="https://wiki.c2.com/?CommandPattern">Command Pattern</a></li>
<li><a rel="nofollow" class="external text" href="https://www.infoworld.com/article/2077569/java-tip-68--learn-how-to-implement-the-command-pattern-in-java.html">Java Tip 68: Learn how to implement the Command pattern in Java</a></li></ul>
<div class="navbox-styles"><style data-mw-deduplicate="TemplateStyles:r1129693374">
/* start https://en.wikipedia.org/ */


.mw-parser-output .hlist dl,.mw-parser-output .hlist ol,.mw-parser-output .hlist ul{margin:0;padding:0}.mw-parser-output .hlist dd,.mw-parser-output .hlist dt,.mw-parser-output .hlist li{margin:0;display:inline}.mw-parser-output .hlist.inline,.mw-parser-output .hlist.inline dl,.mw-parser-output .hlist.inline ol,.mw-parser-output .hlist.inline ul,.mw-parser-output .hlist dl dl,.mw-parser-output .hlist dl ol,.mw-parser-output .hlist dl ul,.mw-parser-output .hlist ol dl,.mw-parser-output .hlist ol ol,.mw-parser-output .hlist ol ul,.mw-parser-output .hlist ul dl,.mw-parser-output .hlist ul ol,.mw-parser-output .hlist ul ul{display:inline}.mw-parser-output .hlist .mw-empty-li{display:none}.mw-parser-output .hlist dt::after{content:": "}.mw-parser-output .hlist dd::after,.mw-parser-output .hlist li::after{content:" · ";font-weight:bold}.mw-parser-output .hlist dd:last-child::after,.mw-parser-output .hlist dt:last-child::after,.mw-parser-output .hlist li:last-child::after{content:none}.mw-parser-output .hlist dd dd:first-child::before,.mw-parser-output .hlist dd dt:first-child::before,.mw-parser-output .hlist dd li:first-child::before,.mw-parser-output .hlist dt dd:first-child::before,.mw-parser-output .hlist dt dt:first-child::before,.mw-parser-output .hlist dt li:first-child::before,.mw-parser-output .hlist li dd:first-child::before,.mw-parser-output .hlist li dt:first-child::before,.mw-parser-output .hlist li li:first-child::before{content:" (";font-weight:normal}.mw-parser-output .hlist dd dd:last-child::after,.mw-parser-output .hlist dd dt:last-child::after,.mw-parser-output .hlist dd li:last-child::after,.mw-parser-output .hlist dt dd:last-child::after,.mw-parser-output .hlist dt dt:last-child::after,.mw-parser-output .hlist dt li:last-child::after,.mw-parser-output .hlist li dd:last-child::after,.mw-parser-output .hlist li dt:last-child::after,.mw-parser-output .hlist li li:last-child::after{content:")";font-weight:normal}.mw-parser-output .hlist ol{counter-reset:listitem}.mw-parser-output .hlist ol>li{counter-increment:listitem}.mw-parser-output .hlist ol>li::before{content:" "counter(listitem)"\a0 "}.mw-parser-output .hlist dd ol>li:first-child::before,.mw-parser-output .hlist dt ol>li:first-child::before,.mw-parser-output .hlist li ol>li:first-child::before{content:" ("counter(listitem)"\a0 "}


/* end https://en.wikipedia.org/ */
</style><style data-mw-deduplicate="TemplateStyles:r1236075235">
/* start https://en.wikipedia.org/ */


.mw-parser-output .navbox{box-sizing:border-box;border:1px solid #a2a9b1;width:100%;clear:both;font-size:88%;text-align:center;padding:1px;margin:1em auto 0}.mw-parser-output .navbox .navbox{margin-top:0}.mw-parser-output .navbox+.navbox,.mw-parser-output .navbox+.navbox-styles+.navbox{margin-top:-1px}.mw-parser-output .navbox-inner,.mw-parser-output .navbox-subgroup{width:100%}.mw-parser-output .navbox-group,.mw-parser-output .navbox-title,.mw-parser-output .navbox-abovebelow{padding:0.25em 1em;line-height:1.5em;text-align:center}.mw-parser-output .navbox-group{white-space:nowrap;text-align:right}.mw-parser-output .navbox,.mw-parser-output .navbox-subgroup{background-color:#fdfdfd}.mw-parser-output .navbox-list{line-height:1.5em;border-color:#fdfdfd}.mw-parser-output .navbox-list-with-group{text-align:left;border-left-width:2px;border-left-style:solid}.mw-parser-output tr+tr>.navbox-abovebelow,.mw-parser-output tr+tr>.navbox-group,.mw-parser-output tr+tr>.navbox-image,.mw-parser-output tr+tr>.navbox-list{border-top:2px solid #fdfdfd}.mw-parser-output .navbox-title{background-color:#ccf}.mw-parser-output .navbox-abovebelow,.mw-parser-output .navbox-group,.mw-parser-output .navbox-subgroup .navbox-title{background-color:#ddf}.mw-parser-output .navbox-subgroup .navbox-group,.mw-parser-output .navbox-subgroup .navbox-abovebelow{background-color:#e6e6ff}.mw-parser-output .navbox-even{background-color:#f7f7f7}.mw-parser-output .navbox-odd{background-color:transparent}.mw-parser-output .navbox .hlist td dl,.mw-parser-output .navbox .hlist td ol,.mw-parser-output .navbox .hlist td ul,.mw-parser-output .navbox td.hlist dl,.mw-parser-output .navbox td.hlist ol,.mw-parser-output .navbox td.hlist ul{padding:0.125em 0}.mw-parser-output .navbox .navbar{display:block;font-size:100%}.mw-parser-output .navbox-title .navbar{float:left;text-align:left;margin-right:0.5em}body.skin--responsive .mw-parser-output .navbox-image img{max-width:none!important}@media print{body.ns-0 .mw-parser-output .navbox{display:none!important}}


/* end https://en.wikipedia.org/ */
</style></div><div role="navigation" class="navbox" aria-labelledby="Software_design_patterns225" style="padding:3px"><table class="nowraplinks mw-collapsible autocollapse navbox-inner" style="border-spacing:0;background:transparent;color:inherit"><tbody><tr><th scope="col" class="navbox-title" colspan="2"><style data-mw-deduplicate="TemplateStyles:r1239400231">
/* start https://en.wikipedia.org/ */


.mw-parser-output .navbar{display:inline;font-size:88%;font-weight:normal}.mw-parser-output .navbar-collapse{float:left;text-align:left}.mw-parser-output .navbar-boxtext{word-spacing:0}.mw-parser-output .navbar ul{display:inline-block;white-space:nowrap;line-height:inherit}.mw-parser-output .navbar-brackets::before{margin-right:-0.125em;content:"[ "}.mw-parser-output .navbar-brackets::after{margin-left:-0.125em;content:" ]"}.mw-parser-output .navbar li{word-spacing:-0.125em}.mw-parser-output .navbar a>span,.mw-parser-output .navbar a>abbr{text-decoration:inherit}.mw-parser-output .navbar-mini abbr{font-variant:small-caps;border-bottom:none;text-decoration:none;cursor:inherit}.mw-parser-output .navbar-ct-full{font-size:114%;margin:0 7em}.mw-parser-output .navbar-ct-mini{font-size:114%;margin:0 4em}html.skin-theme-clientpref-night .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}@media(prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .navbar li a abbr{color:var(--color-base)!important}}@media print{.mw-parser-output .navbar{display:none!important}}


/* end https://en.wikipedia.org/ */
</style><div id="Software_design_patterns225" style="font-size:114%;margin:0 4em"><a href="Software_design_pattern" title="Software design pattern">Software design patterns</a></div></th></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Design_Patterns" title="Design Patterns">Gang of Four<br>patterns</a></th><td class="navbox-list-with-group navbox-list navbox-odd hlist" style="width:100%;padding:0"><div style="padding:0 0.25em"></div><table class="nowraplinks navbox-subgroup" style="border-spacing:0"><tbody><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Creational_pattern" title="Creational pattern">Creational</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Abstract_factory_pattern" title="Abstract factory pattern">Abstract factory</a></li>
<li><a href="Builder_pattern" title="Builder pattern">Builder</a></li>
<li><a href="Factory_method_pattern" title="Factory method pattern">Factory method</a></li>
<li><a href="Prototype_pattern" title="Prototype pattern">Prototype</a></li>
<li><a href="Singleton_pattern" title="Singleton pattern">Singleton</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Structural_pattern" title="Structural pattern">Structural</a></th><td class="navbox-list-with-group navbox-list navbox-even" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Adapter_pattern" title="Adapter pattern">Adapter</a></li>
<li><a href="Bridge_pattern" title="Bridge pattern">Bridge</a></li>
<li><a href="Composite_pattern" title="Composite pattern">Composite</a></li>
<li><a href="Decorator_pattern" title="Decorator pattern">Decorator</a></li>
<li><a href="Facade_pattern" title="Facade pattern">Facade</a></li>
<li><a href="Flyweight_pattern" title="Flyweight pattern">Flyweight</a></li>
<li><a href="Proxy_pattern" title="Proxy pattern">Proxy</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Behavioral_pattern" title="Behavioral pattern">Behavioral</a></th><td class="navbox-list-with-group navbox-list navbox-odd" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Chain-of-responsibility_pattern" title="Chain-of-responsibility pattern">Chain of responsibility</a></li>

<li><a href="Interpreter_pattern" title="Interpreter pattern">Interpreter</a></li>
<li><a href="Iterator_pattern" title="Iterator pattern">Iterator</a></li>
<li><a href="Mediator_pattern" title="Mediator pattern">Mediator</a></li>
<li><a href="Memento_pattern" title="Memento pattern">Memento</a></li>
<li><a href="Observer_pattern" title="Observer pattern">Observer</a></li>
<li><a href="State_pattern" title="State pattern">State</a></li>
<li><a href="Strategy_pattern" title="Strategy pattern">Strategy</a></li>
<li><a href="Template_method_pattern" title="Template method pattern">Template method</a></li>
<li><a href="Visitor_pattern" title="Visitor pattern">Visitor</a></li></ul>
</div></td></tr></tbody></table><div></div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Concurrency_pattern" title="Concurrency pattern">Concurrency<br>patterns</a></th><td class="navbox-list-with-group navbox-list navbox-even hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Active_object" title="Active object">Active object</a></li>
<li><a href="Balking_pattern" title="Balking pattern">Balking</a></li>
<li><a href="Binding_properties_pattern" title="Binding properties pattern">Binding properties</a></li>
<li><a href="Double-checked_locking" title="Double-checked locking">Double-checked locking</a></li>
<li><a href="Asynchronous_method_invocation" title="Asynchronous method invocation">Event-based asynchronous</a></li>
<li><a href="Guarded_suspension" title="Guarded suspension">Guarded suspension</a></li>
<li><a href="Join-pattern" title="Join-pattern">Join</a></li>
<li><a href="Lock_(computer_science)" title="Lock (computer science)">Lock</a></li>
<li><a href="Monitor_(synchronization)" title="Monitor (synchronization)">Monitor</a></li>
<li><a href="Proactor_pattern" title="Proactor pattern">Proactor</a></li>
<li><a href="Reactor_pattern" title="Reactor pattern">Reactor</a></li>
<li><a href="Readers%E2%80%93writer_lock" title="Readers–writer lock">Read–write lock</a></li>
<li><a href="Scheduler_pattern" class="mw-redirect" title="Scheduler pattern">Scheduler</a></li>
<li><a href="Scheduled-task_pattern" title="Scheduled-task pattern">Scheduled-task pattern</a></li>
<li><a href="Semaphore_(programming)" title="Semaphore (programming)">Semaphore</a></li>
<li><a href="Thread_pool" title="Thread pool">Thread pool</a></li>
<li><a href="Thread-local_storage" title="Thread-local storage">Thread-local storage</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%"><a href="Architectural_pattern" title="Architectural pattern">Architectural<br>patterns</a></th><td class="navbox-list-with-group navbox-list navbox-odd hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Front_controller" title="Front controller">Front controller</a></li>
<li><a href="Interceptor_pattern" title="Interceptor pattern">Interceptor</a></li>
<li><a href="Model%E2%80%93view%E2%80%93controller" title="Model–view–controller">MVC</a>
<ul><li><a href="Model%E2%80%93view%E2%80%93presenter" title="Model–view–presenter">MVP</a></li>
<li><a href="Model%E2%80%93view%E2%80%93viewmodel" title="Model–view–viewmodel">MVVM</a></li></ul></li>
<li><a href="Action%E2%80%93domain%E2%80%93responder" title="Action–domain–responder">ADR</a></li>
<li><a href="Entity_component_system" title="Entity component system">ECS</a></li>
<li><a href="Multitier_architecture" title="Multitier architecture"><i>n</i>-tier</a></li>
<li><a href="Specification_pattern" title="Specification pattern">Specification</a></li>
<li><a href="Publish%E2%80%93subscribe_pattern" title="Publish–subscribe pattern">Publish–subscribe</a></li>
<li><a href="Naked_objects" title="Naked objects">Naked objects</a></li>
<li><a href="Service_locator_pattern" title="Service locator pattern">Service locator</a></li>
<li><a href="Active_record_pattern" title="Active record pattern">Active record</a></li>
<li><a href="Identity_map_pattern" title="Identity map pattern">Identity map</a></li>
<li><a href="Data_access_object" title="Data access object">Data access object</a></li>
<li><a href="Data_transfer_object" title="Data transfer object">Data transfer object</a></li>
<li><a href="Inversion_of_control" title="Inversion of control">Inversion of control</a></li>
<li><a href="JSP_model_2_architecture" title="JSP model 2 architecture">Model 2</a></li>
<li><a href="Broker_pattern" title="Broker pattern">Broker</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Other<br>patterns</th><td class="navbox-list-with-group navbox-list navbox-even hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Blackboard_design_pattern" class="mw-redirect" title="Blackboard design pattern">Blackboard</a></li>
<li><a href="Business_delegate_pattern" title="Business delegate pattern">Business delegate</a></li>
<li><a href="Composite_entity_pattern" title="Composite entity pattern">Composite entity</a></li>
<li><a href="Dependency_injection" title="Dependency injection">Dependency injection</a></li>
<li><a href="Guard_(computer_science)" title="Guard (computer science)">Guard clause</a></li>
<li><a href="Intercepting_filter_pattern" title="Intercepting filter pattern">Intercepting filter</a></li>
<li><a href="Lazy_loading" title="Lazy loading">Lazy loading</a></li>
<li><a href="Mock_object" title="Mock object">Mock object</a></li>
<li><a href="Null_object_pattern" title="Null object pattern">Null object</a></li>
<li><a href="Object_pool_pattern" title="Object pool pattern">Object pool</a></li>
<li><a href="Servant_(design_pattern)" title="Servant (design pattern)">Servant</a></li>
<li><a href="Twin_pattern" title="Twin pattern">Twin</a></li>
<li><a href="Type_Tunnel_pattern" class="mw-redirect" title="Type Tunnel pattern">Type tunnel</a></li>
<li><a href="Method_chaining" title="Method chaining">Method chaining</a></li>
<li><a href="Delegation_pattern" title="Delegation pattern">Delegation</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Books</th><td class="navbox-list-with-group navbox-list navbox-odd hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><i><a href="Design_Patterns" title="Design Patterns">Design Patterns</a></i></li>
<li><i><a href="Enterprise_Integration_Patterns" title="Enterprise Integration Patterns">Enterprise Integration Patterns</a></i></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">People</th><td class="navbox-list-with-group navbox-list navbox-even hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Christopher_Alexander" title="Christopher Alexander">Christopher Alexander</a></li>
<li><a href="Erich_Gamma" title="Erich Gamma">Erich Gamma</a></li>
<li><a href="Ralph_Johnson_(computer_scientist)" title="Ralph Johnson (computer scientist)">Ralph Johnson</a></li>
<li><a href="John_Vlissides" title="John Vlissides">John Vlissides</a></li>
<li><a href="Grady_Booch" title="Grady Booch">Grady Booch</a></li>
<li><a href="Kent_Beck" title="Kent Beck">Kent Beck</a></li>
<li><a href="Ward_Cunningham" title="Ward Cunningham">Ward Cunningham</a></li>
<li><a href="Martin_Fowler_(software_engineer)" title="Martin Fowler (software engineer)">Martin Fowler</a></li>
<li><a href="Robert_C._Martin" title="Robert C. Martin">Robert Martin</a></li>
<li><a href="Jim_Coplien" title="Jim Coplien">Jim Coplien</a></li>
<li><a href="Douglas_C._Schmidt" title="Douglas C. Schmidt">Douglas Schmidt</a></li>
<li><a href="Linda_Rising" title="Linda Rising">Linda Rising</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">Communities</th><td class="navbox-list-with-group navbox-list navbox-odd hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="The_Hillside_Group" title="The Hillside Group">The Hillside Group</a></li>
<li><a href="Portland_Pattern_Repository" title="Portland Pattern Repository">Portland Pattern Repository</a></li></ul>
</div></td></tr><tr><th scope="row" class="navbox-group" style="width:1%">See also</th><td class="navbox-list-with-group navbox-list navbox-even hlist" style="width:100%;padding:0"><div style="padding:0 0.25em">
<ul><li><a href="Anti-pattern" title="Anti-pattern">Anti-pattern</a></li>
<li><a href="Architectural_pattern" title="Architectural pattern">Architectural pattern</a></li></ul>
</div></td></tr></tbody></table></div></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-05-19" href="https://en.wikipedia.org/wiki/?title=Command_pattern&amp;oldid=1291107478">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>

</body></html>